package cn.weekimwee.firstlineofcodeforkotlin.unit5

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.support.v7.app.AlertDialog
import cn.weekimwee.firstlineofcodeforkotlin.ActivityCollector
import cn.weekimwee.firstlineofcodeforkotlin.MainActivity
import org.jetbrains.anko.startActivity

/**
 * Created by Wee Kim Wee on 2018/2/17.
 */
class GoBackReceiver :BroadcastReceiver(){
    override fun onReceive(context: Context, intent: Intent?) {
        AlertDialog.Builder(context)
                .apply {
                    setTitle("warning")
                    setMessage("go back message")
                    setCancelable(false)
                    setPositiveButton("ok") { _, _ ->
                        ActivityCollector.finishAll()
                        context.startActivity<MainActivity>()
                    }
                }
                .show()
    }
}